<?php

/*
** COMITATO PROVINCIALE CATANIA - CROCE ROSSA ITALIANA
*/

class Autocompletamento {
	public
		$termine = '',
		$nomeCampo = NULL;
	private
		$db;
	public function __construct( $nomeCampo ) {
		global $db;
		$this->db = $db;
		$this->nomeCampo = $nomeCampo;
	}
	public function risultati( $num = NULL ) {
		$valore = $this->db->escape($this->termine);
		$q = "SELECT valore
			  FROM
				autocompletamento
			  WHERE
				nome='{$this->nomeCampo}'
				 AND
				valore LIKE '%{$valore}%'
			  ORDER BY
				valore ASC";
		if ( $num ) {
			 $q .= " LIMIT $num";
		}
		$q = $this->db->query($q);
		if (!$q) { return array(); }
		$t = array();
		while ($r = $this->db->fetch_array($q)) {
			$t[] = $r[0];
		}
		return $t;
	}
}
		
	